package com.biboheart.adapter.compiler.enums;

import com.biboheart.adapter.support.BaseEnum;
import com.biboheart.adapter.support.EnumValueObject;

import java.util.ArrayList;
import java.util.List;

public enum TokenLevel implements BaseEnum<String, Integer> {
    TOKEN_LEVEL_01("tag", 1),
    TOKEN_LEVEL_02("(", 2),
    TOKEN_LEVEL_03("keyword", 3),
    TOKEN_LEVEL_04("*", 5),
    TOKEN_LEVEL_05("/", 5),
    TOKEN_LEVEL_06("%", 5),
    TOKEN_LEVEL_07("+", 6),
    TOKEN_LEVEL_08("-", 6),
    TOKEN_LEVEL_09("<<", 7),
    TOKEN_LEVEL_10(">>", 7),
    TOKEN_LEVEL_11(">", 8),
    TOKEN_LEVEL_12(">=", 8),
    TOKEN_LEVEL_13("<", 8),
    TOKEN_LEVEL_14("<=", 8),
    TOKEN_LEVEL_15("==", 9),
    TOKEN_LEVEL_16("!=", 9),
    TOKEN_LEVEL_17("&", 10),
    TOKEN_LEVEL_18("^", 11),
    TOKEN_LEVEL_19("|", 12),
    TOKEN_LEVEL_20("&&", 13),
    TOKEN_LEVEL_21("||", 14),
    ;
    private final String code;
    private final Integer level;

    TokenLevel(String code, Integer level) {
        this.code = code;
        this.level = level;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public Integer desc() {
        return level;
    }

    public static TokenLevel getLevel(String code) {
        for (TokenLevel tokenLevel : values()) {
            if (tokenLevel.code().equals(code)) {
                return tokenLevel;
            }
        }
        return null;
    }

    public static boolean contains(String code) {
        for (TokenLevel tokenLevel : values()) {
            if (tokenLevel.code().equals(code)) {
                return true;
            }
        }
        return false;
    }

    public static List<EnumValueObject<String, Integer>> list() {
        List<EnumValueObject<String, Integer>> list = new ArrayList<>();
        for (TokenLevel tokenLevel : values()) {
            list.add(new EnumValueObject<>(tokenLevel.code(), tokenLevel.desc()));
        }
        return list;
    }
}
